import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTabbedPane;
import javax.swing.JList;
import javax.swing.JTextArea;
import javax.swing.border.CompoundBorder;


public class EITerapeutaBilatu extends JFrame {

	private JPanel contentPane;
	private JTextField nanSartu;
	private JButton bilatu;
	private JButton atzera;
	private JButton logout;
	private Taula taula;
	private JButton terapeutaEzabatu;
	private JButton gehitu;
	private JTextField espezialitatea;
	private JTextArea textArea;


	public EITerapeutaBilatu() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 900, 600);
		setVisible(true);
		elementuakHasieratu();
		botoiakHasieratu();
		
	}
	
	public void elementuakHasieratu(){

		
		contentPane = new JPanel();
		contentPane.setBorder(new CompoundBorder());
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblTerapeutarenNan = new JLabel("Terapeutaren nan:");
		lblTerapeutarenNan.setBounds(100, 42, 147, 15);
		contentPane.add(lblTerapeutarenNan);
		
		nanSartu = new JTextField();
		nanSartu.setBounds(243, 42, 114, 15);
		contentPane.add(nanSartu);
		nanSartu.setColumns(10);
		
		bilatu = new JButton("Bilatu");
		bilatu.setBounds(382, 37, 117, 25);
		contentPane.add(bilatu);
		
		logout = new JButton("Logout");
		logout.setBounds(796, 0, 84, 25);
		contentPane.add(logout);
		
		atzera = new JButton("Atzera");
		atzera.setBounds(796, 514, 84, 25);
		contentPane.add(atzera);
		
		Vector<String> izenak = new Vector<String>();
		izenak.addElement("NAN");
		izenak.addElement("Izena");
		izenak.addElement("Abizena");
		izenak.addElement("Pasahitza");
		taula = new Taula(izenak);
		taula.setBounds(85, 69, 418, 411);
		contentPane.add(taula);
		
		terapeutaEzabatu = new JButton("Terapeuta ezabatu");
		terapeutaEzabatu.setBounds(255, 494, 185, 25);
		contentPane.add(terapeutaEzabatu);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(221, 209, -73, -18);
		contentPane.add(tabbedPane);
		
		JLabel lblEspezialitateak = new JLabel("Espezialitateak");
		lblEspezialitateak.setBounds(608, 42, 126, 15);
		contentPane.add(lblEspezialitateak);
		
		textArea = new JTextArea();
		textArea.setBounds(587, 80, 147, 182);
		contentPane.add(textArea);
		
		JLabel lblEspezialitateaGehitu = new JLabel("Espezialitatea gehitu:");
		lblEspezialitateaGehitu.setBounds(585, 303, 167, 15);
		contentPane.add(lblEspezialitateaGehitu);
		
		espezialitatea = new JTextField();
		espezialitatea.setBounds(689, 350, 114, 19);
		contentPane.add(espezialitatea);
		espezialitatea.setColumns(10);
		
		JLabel lblEspezialitatea = new JLabel("Espezialitatea:");
		lblEspezialitatea.setBounds(555, 352, 107, 15);
		contentPane.add(lblEspezialitatea);
		
		gehitu = new JButton("Gehitu");
		gehitu.setBounds(617, 398, 117, 25);
		contentPane.add(gehitu);

	}
	
	public void botoiakHasieratu(){
		bilatu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				Terapeuta t = TerapeutaKudeatzailea.getInstantzia().terapeutaBilatu(nanSartu.getText());
				pantailaratu(t);
				Vector<String> lista = TerapeutaKudeatzailea.getInstantzia().getEspezialitateak(nanSartu.getText());
				textArea.removeAll();
				String mezua ="";
				for (String esp:lista){
					mezua = mezua +esp + "\n";
				}
				
				textArea.setText(mezua);
			}
		});
		
		terapeutaEzabatu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				TerapeutaKudeatzailea.getInstantzia().terapeutaEzabatu(nanSartu.getText());
			
			}
		});
		
		
		atzera.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				//EIIdazkari frame = new EIIdazkari();
				EITerapeutakKudeatu frame = new EITerapeutakKudeatu();
				EITerapeutaBilatu.this.dispose();
			}
		});
		
		logout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				EILogin frame = new EILogin();
				EITerapeutaBilatu.this.dispose();
			}
		});
		
		gehitu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				TerapeutaKudeatzailea.getInstantzia().espezialitateaGehitu(nanSartu.getText(),espezialitatea.getText());
			}
		});
	}
	public void pantailaratu(Terapeuta t){	
							
			taula.lerroaGehitu(t);
			
		
	}
}
